# ------------------------------------------------------------
# Purpose: Create all tables and figures of the analysis.
# Usage:   Source this script to generate all tables and figures.
# ------------------------------------------------------------

# Some tables/figures use restricted access data
restricted_tables <- c(1, 3:4, 6:7)
restricted_appendix_tables <- c(2, 8:9, 11:12, 14:15, 17, 19:20, 22:23, 25:26, 28:29, 31:32, 34:35, 37:38, 40:41, 44, 46:51, 54)
restricted_appendix_figures <- c(1, 5:6, 14:15)


# Create tables
lapply(1:9, function(i) {
    if (!(i %in% restricted_tables)) {
        cat(paste0("Processing table0", i, ".r...\n"))
        source(file.path(project_dir, "code", paste0("table0", i, ".r")))
    } else {
        cat(paste0("Skipping table0", i, ".r (restricted access data)\n"))
    }
})


# Create figures
source(file.path(project_dir, "code", "figure01.r"))


# Create appendix tables
lapply(1:54, function(i) {
    if (!(i %in% restricted_appendix_tables)) {
        filename <- ifelse(
            i < 10,
            paste0("tableB0", i, ".r"),
            paste0("tableB", i, ".r")
        )
        cat(paste0("Processing ", filename, "...\n"))
        source(file.path(project_dir, "code", filename))
    } else {
        cat(paste0("Skipping tableB", ifelse(i < 10, "0", ""), i, ".r (restricted access data)\n"))
    }
})


# Create appendix figures
lapply(1:15, function(i) {
    if (!(i %in% restricted_appendix_figures)) {
        filename <- ifelse(
            i < 10,
            paste0("figureB0", i, ".r"),
            paste0("figureB", i, ".r")
        )
        cat(paste0("Processing ", filename, "...\n"))
        source(file.path(project_dir, "code", filename))
    } else {
        cat(paste0("Skipping figureB", ifelse(i < 10, "0", ""), i, ".r (restricted access data)\n"))
    }
})
